import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/constant/constant.dart';
import 'package:distribution_mall_flutter/constant/point_constant.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/provider/order/order_list.dart';
import 'package:distribution_mall_flutter/router/route_utils.dart';
import 'package:distribution_mall_flutter/utils/common_third.dart';
import 'package:distribution_mall_flutter/utils/common_widget.dart';
import 'package:distribution_mall_flutter/utils/firebase/firebase_analytics_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class OrderListNav extends ConsumerWidget {
  OrderListNav({super.key});
  final TextEditingController _textEditingController = TextEditingController();
  final List<Tab> orderTabs =
      tabMap.map((item) => Tab(text: item['label'])).toList();

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return SliverAppBar(
      pinned: true,
      floating: false,
      // expandedHeight: 100.0,
      // elevation: 0,
      // backgroundColor: Colors.white,
      // forceMaterialTransparency: true,
      // snap: true,
      leading: CommonBtnWidget.arrowBack(onPressed: () {
        RouteUtils.back();
      }),
      // flexibleSpace: FlexibleSpaceBar(
      //   background: Container(
      //     color: Colors.white, // 设置固定的背景颜色
      //   ),
      // ),
      flexibleSpace: Container(
        color: Colors.white, // AppBar的颜色
      ),
      actions: [
        Expanded(
            child: Container(
          height: 44,
          padding: const EdgeInsets.symmetric(horizontal: EdgeConstant.edge20),
          margin: const EdgeInsets.only(
              left: EdgeConstant.edge30, right: EdgeConstant.edge5),
          child: TextField(
            controller: _textEditingController,
            onEditingComplete: () {
              ref.read(orderListProvider.notifier).setParamsAndRefresh(
                  {'channelOrderNo': _textEditingController.text});
            },
            textAlign: TextAlign.left,
            textAlignVertical: TextAlignVertical.center,
            decoration: InputDecoration(
              hintText: S.of(context).searchAnything,
              prefixIcon: const Icon(Icons.search),
              filled: true,
              fillColor: ColorConstant.grey246,
              hintStyle: const TextStyle(
                  color: Color.fromRGBO(168, 168, 167, 1),
                  textBaseline: TextBaseline.alphabetic, // 设置文本基线为基准线
                  height: 1),
            ),
            style: const TextStyle(
              fontSize: FontConstant.f13, // 设置字体大小为20
            ),
          ),
        )
            //     Row(
            //   children: [
            //     ,
            //     // TextButton(
            //     //     onPressed: () {},
            //     //     child: Text(
            //     //       S.of(context).filter,
            //     //       style: const TextStyle(
            //     //           color: Colors.black, fontSize: FontConstant.f13),
            //     //     ))
            //   ],
            // )
            ),
      ],
      bottom: PreferredSize(
        preferredSize: const Size.fromHeight(kToolbarHeight),
        child: DefaultTabController(
          length: orderTabs.length,
          child: TabBar(
            onTap: (index) {
              EPLoading.showLoadig();
              ref
                  .read(orderListProvider.notifier)
                  .setParams({'state': tabMap[index]['value']});
              ref.read(orderListProvider.notifier).refresh();
              // FirebaseAnalyticsUtils.logEvent(
              //     name: PointConstant.orderTab,
              //     parameters: {'orderState': tabMap[index]['label']});
            },
            tabAlignment: TabAlignment.start,
            dividerColor: Colors.transparent,
            labelStyle: const TextStyle(
                fontSize: FontConstant.f16,
                fontWeight: FontWeight.bold,
                color: Colors.black),
            unselectedLabelStyle: const TextStyle(
                fontWeight: FontWeight.normal, color: ColorConstant.black51),
            indicator: const BoxDecoration(
                border: Border(
                    bottom: BorderSide(
                        color: ColorConstant.primaryColor, width: 2))),
            tabs: orderTabs,
            isScrollable: true,
          ),
        ),
      ),
    );
  }
}
